package practice.p4;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class Servers {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket=new ServerSocket(10000);

        Socket socket = serverSocket.accept();

        BufferedInputStream bis=new BufferedInputStream(socket.getInputStream());
        String name = UUID.randomUUID().toString().replace("-", "");
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("MyWebSocket\\server\\"+name+".jpg"));

        int len;
        byte [] bytes=new byte[1024];
        while ((len=bis.read(bytes))!=-1){
            bos.write(bytes,0,len);

        }
        bos.flush();
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

        bw.write("上传成功");
        bw.newLine();
        bw.flush();

        socket.close();
        serverSocket.close();
    }
}
